package com.wzl.customviewproject.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wzl.customviewproject.R;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者：longxiansen
 * 功能：
 */
public class ParentListAdapter extends RecyclerView.Adapter<ParentListAdapter.ParentItemViewHolder> {
    private Context mContext;
    private List<String> dataList = new ArrayList<>();

    public ParentListAdapter(Context mContext, List<String> dataList) {
        this.mContext = mContext;
        this.dataList = dataList;
    }

    @Override
    public void onViewRecycled(@NonNull @NotNull ParentListAdapter.ParentItemViewHolder holder) {
        super.onViewRecycled(holder);
        Log.d("ADADAA", "onViewRecycled: ");
    }

    @Override
    public void onViewAttachedToWindow(@NonNull @NotNull ParentListAdapter.ParentItemViewHolder holder) {
        super.onViewAttachedToWindow(holder);
        Log.d("ADADAA", "onViewAttachedToWindow: ");
    }

    @Override
    public void onViewDetachedFromWindow(@NonNull @NotNull ParentListAdapter.ParentItemViewHolder holder) {
        super.onViewDetachedFromWindow(holder);
        Log.d("ADADAA", "onViewDetachedFromWindow: ");
    }

    @Override
    public void onAttachedToRecyclerView(@NonNull @NotNull RecyclerView recyclerView) {
        super.onAttachedToRecyclerView(recyclerView);
        Log.d("ADADAA", "onAttachedToRecyclerView: ");
    }

    @Override
    public void onDetachedFromRecyclerView(@NonNull @NotNull RecyclerView recyclerView) {
        super.onDetachedFromRecyclerView(recyclerView);
        Log.d("ADADAA", "onDetachedFromRecyclerView: ");

    }

    @NonNull
    @org.jetbrains.annotations.NotNull
    @Override
    public ParentItemViewHolder onCreateViewHolder(@NonNull @org.jetbrains.annotations.NotNull ViewGroup parent, int viewType) {
        return new ParentItemViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_parent_list,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull @org.jetbrains.annotations.NotNull ParentListAdapter.ParentItemViewHolder holder, int position) {
        holder.tv.setText(dataList.get(position));
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    class ParentItemViewHolder extends RecyclerView.ViewHolder{
        TextView tv;
        public ParentItemViewHolder(@NonNull @org.jetbrains.annotations.NotNull View itemView) {
            super(itemView);
            tv = itemView.findViewById(R.id.name);
        }
    }
}
